////////////////////////////////////////////////
// DESCRIPTION:
//     Class for Windows CE Message Queues
//
// Legal Notices:
//     Copyright (c) 2008, Telliam Consulting, LLC.
//     All rights reserved.
//
//     Redistribution and use in source and binary forms, with or without modification,
//     are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright notice,
//       this list of conditions and the following disclaimer.
//
//     * Redistributions in binary form must reproduce the above copyright notice,
//       this list of conditions and the following disclaimer in the documentation
//       and/or other materials provided with the distribution.
//
//     * Neither the name of Telliam Consulting nor the names of its contributors
//       may be used to endorse or promote products derived from this software
//       without specific prior written permission.
//
// Disclaimer:
//     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
//     ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
//     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
//     IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
//     INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
//     BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
//     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
//     LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
//     OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
//     OF THE POSSIBILITY OF SUCH DAMAGE.  
//
#pragma once
#include <msgqueue.h>
#include "Handle.h"

namespace FusionWare
{
    namespace Win32
    {
        ///////////////////////////////////////////////////////
        // Description: 
        //    Class to manage a Win32 Peer-to-Peer Message Queues
        //
        class CMsgQueue : public FusionWare::Win32::TWin32Handle<NULL>
        {
        public:
            CMsgQueue()  {}
            ~CMsgQueue() {}

            CMsgQueue(const CMsgQueue& Src) 
                : FusionWare::Win32::TWin32Handle<NULL>(Src)
            {
            }

            CMsgQueue& operator=(HANDLE h)           { FusionWare::Win32::TWin32Handle<NULL>::operator=(h); return *this;}
            CMsgQueue& operator=(const CMsgQueue& R) { FusionWare::Win32::TWin32Handle<NULL>::operator=(R); return *this;}

            ///////////////////////////////////////////////////////
            // Description: 
            //    Creates a Read Only Message Queue
            //
            // Input: 
            //    MsgSize       - Size for each message in the queue
            //    MaxMessages=0 - Maximum number of Messages (0 indicates no limit)
            //    Flags=0       - flags (See MSGQUEUEOPTIONS in standard help)
            //    Name          - Name for the Queue or NULL if none needed
            //
            // Remarks: 
            //     
            // Note: 
            //     
            bool CreateReadOnly(DWORD MsgSize, DWORD MaxMessages=0, DWORD Flags=0, const TCHAR* Name=NULL );

            ///////////////////////////////////////////////////////
            // Description: 
            //    Creates a Write Only Message Queue
            //
            // Input: 
            //    MsgSize       - Size for each message in the queue
            //    MaxMessages=0 - Maximum number of Messages (0 indicates no limit)
            //    Flags=0       - flags (See MSGQUEUEOPTIONS in standard help)
            //    Name          - Name for the Queue or NULL if none needed
            //
            // Remarks: 
            //     
            // Note: 
            //     
            bool CreateWriteOnly(DWORD MsgSize, DWORD MaxMessages=0, DWORD Flags=0, const TCHAR* Name=NULL );

            ///////////////////////////////////////////////////////
            // Description: 
            //    Reads a message from the Queue
            // 
            // Input: 
            //    pBuffer   - pointer to where to place the data read
            //    Size      - size of region pointed to by pBuffer
            //    pNumRead  - pointer to actual number of bytes written into pBuffer
            //    pFlags    - Flags for the message
            //    Timeout=0 - Timeout in ms for the read
            //
            // Remarks: 
            //     
            // Note: 
            //     
            bool Read(void* pBuffer, DWORD Size, DWORD* pNumRead, DWORD* pFlags, DWORD Timeout=0);
        };
    }
}